USE aslb
GO
/************************************************************************************************
File  : UnInstallASLBMonitor.sql
Author: Jocaplan
Date  : 04/22/2009
Decr  : this script UnInstalls all assemblies for ASLBMonitor
List of drop CLRs:
   dbo.CheckServerAvailability
   dbo.CheckServerPerformance
********************************************************************************
** Change History
********************************************************************************
** Date        Author     Description
** ----------  ---------  -----------------------------------------------------

*******************************************************************************/
SET NOCOUNT ON
SET QUOTED_IDENTIFIER ON
SET ANSI_WARNINGS ON
SET ANSI_PADDING ON
SET ANSI_NULLS ON
SET CONCAT_NULL_YIELDS_NULL ON

DECLARE @err int
       ,@rc  int
       ,@rows int
       ,@errordescr varchar(255)




-----------------------------------------------------------------------
IF EXISTS(SELECT * FROM sys.assemblies WHERE name = 'Microsoft.AnalysisServices')
BEGIN

   IF OBJECT_ID('dbo.CheckServerAvailability') IS NOT NULL
   BEGIN
      DROP Procedure dbo.CheckServerAvailability
      SELECT @err = @@ERROR
            ,@rows = @@ROWCOUNT
            ,@errordescr = 'Failed to drop procedure CheckServerAvailability.'
      IF @err <> 0 GOTO ErrorHandler
      RAISERROR('Successfully dropped procedure CheckServerAvailability.', 0,1) WITH NOWAIT
   END
   ELSE
      RAISERROR('Procedure CheckServerAvailability already dropped.', 0,1) WITH NOWAIT

   IF OBJECT_ID('dbo.CheckServerPerformance') IS NOT NULL
   BEGIN
      DROP Procedure dbo.CheckServerPerformance
      SELECT @err = @@ERROR
            ,@rows = @@ROWCOUNT
            ,@errordescr = 'Failed to drop procedure CheckServerPerformance.'
      IF @err <> 0 GOTO ErrorHandler
      RAISERROR('Successfully dropped procedure CheckServerPerformance.', 0,1) WITH NOWAIT
   END
   ELSE
      RAISERROR('Procedure CheckServerPerformance already dropped.', 0,1) WITH NOWAIT


   DROP ASSEMBLY ASLBMonitor
   SELECT @err = @@ERROR
         ,@rows = @@ROWCOUNT
         ,@errordescr = 'Failed to drop assembly ASLBMonitor.'
   IF @err <> 0 GOTO ErrorHandler

   RAISERROR('Successfully dropped assembly ASLBMonitor.', 0,1) WITH NOWAIT

   DROP ASSEMBLY [Microsoft.AnalysisServices]
   SELECT @err = @@ERROR
         ,@rows = @@ROWCOUNT
         ,@errordescr = 'Failed to drop assembly AnalysisServices.'
   IF @err <> 0 GOTO ErrorHandler

   RAISERROR('Successfully dropped assembly AnalysisServices.', 0,1) WITH NOWAIT
END
ELSE
   RAISERROR('Assemblies are already dropped!', 0,1) WITH NOWAIT


GOTO NextStep

ErrorHandler:

RAISERROR('',0,1) WITH NOWAIT
RAISERROR(@errordescr, 18,127)
RAISERROR('Failed Running script UnInstallASLBMonitor.sql', 0,1) WITH NOWAIT

-------------------------------------------------------------------------------------
NextStep:
go


